<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class partidoModel extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }
    
     public function getAll(){
         $this->db->order_by("partido", "asc");
         $query = $this->db->get('partidos');
        return $query->result();
    }
    
    public function get($id){
        $this->db->where('id', $id);
         $query = $this->db->get('partidos');
        $result = $query->result();
        return $result[0];
    }
    
    public function update($id,$partido ){
         $sql = "UPDATE partidos SET partido = '$partido'
        WHERE id = $id";
         
        $this->db->query($sql);
        
        if($this->db->affected_rows() > 0){
            return 1;
        }else{
            return 0;
        }
       
    }
    
     public function delete($id){
        $this->db->where('id', $id);
        $q = $this->db->delete('partidos'); 
        return $q;
     }
    
   public function create($localidad){
         $sql = "INSERT INTO partidos (partido) 
        VALUES ('$localidad')";

        $this->db->query($sql);
        if($this->db->affected_rows() > 0){
            return $this->db->insert_id();
        }else{
            return $this->db->affected_rows();
        }
   }
    
   
}